#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/wait.h>
#include<openssl/err.h>
#include<string.h>
#include<signal.h>

#define MAXLINE 4688

static void sig_int(int);

int main(void){
	char buf[MAXLINE];
	pid_t pid;
	int status;
	
	if(signal(SIGINT, sig_int) == SIG_ERR){
		perror("signal error");
		exit(1);
	}

	printf("%% ");
	while(fgets(buf, MAXLINE, stdin) != NULL){
		if(buf[strlen(buf)-1] == '\n')
			buf[strlen(buf)-1] = 0;
		
		if((pid = fork()) < 0){
			printf("fork error : ");
			printf("%s\n", strerror(errno));
			exit(1);
		}else if(pid == 0){
			execlp(buf, buf, (char*)0);
			printf("couldn't excute : %s : ", buf);
			printf("%s\n", strerror(errno));
			exit(127);
		}

		if((pid = waitpid(pid, &status, 0)) < 0){
			printf("waitpid error : ");
			printf("%s\n", strerror(errno));
			exit(1);
		}
		
		printf("%% ");
	}
	exit(0);
}

void sig_int(int signo){
	printf("interrupt\n%% ");
}
